home *** CD-ROM | disk | FTP | other *** search
/ Megahits 3 / Megahits 3 (1994)(GTI - Rhein-Main-Soft)(DE)[!].iso / module / moremods / defrag11.mod < prev    next >
Text File  |  1994-10-14  |  20KB  |  722 lines

  1. DEFRAG.C v1.10 Source Code                         <Program>
  2. East Bay Ray #1 @9964
  3. Wed Jan 01 18:18:33 1992
  4. /*  DEFRAGMENT WWIV TYPE-2 MESSAGE BASES */
  5.  
  6. /*  Written by Jeff Garzik (East Bay Ray), 11-24-1991                    */
  7. /*  Copyright (c) 1991 Jeff M. Garzik                                    */
  8. /*  Compiled and tested using Borland C++ - Version 2.0                  */
  9. /*  License granted to freely distribute without compensation and to     */
  10. /*  modify as needed "to get the job done."  Use at your own risk.       */
  11. /*  Distributed "as is".  No warranty or guarantee.                      */
  12. /*  Cannot be used or sold COMMERCIALLY without prior written permission */
  13. /*  of the author, Jeff Garzik.                                          */
  14. /*  Portions Copyright (c) 1988-1991 by Wayne Bell.                      */
  15.  
  16. /*  Jeff Garzik    v1.00     Initial Release.                            */
  17. /*  Jeff Garzik    v1.10     Searches correct drive for free space.      */
  18. /*                           Processes command line arguments /E, /C.    */
  19. /*                           Compresses EMAIL.DAT.                       */
  20. /*                           Processes command line argument /O.         */
  21. /*                           Prints out report upon completion.          */
  22. /*                           Removes messages with no text.              */
  23. /*                           Automated mode support shell added.  No     */
  24. /*                             real code is in place for this one.  This */
  25. /*                             will be for the "fix" feature in the next */
  26. /*                             release of the program.  If automated     */
  27. /*                             mode is on, then the program will not ask */
  28. /*                             any questions like FIX does, and will     */
  29. /*                             simply assume you want these fixed (or    */
  30. /*                             not fixed, depending on how you set your  */
  31. /*                             options).                                 */
  32.  
  33. /*  Compile using "bcc -ml defrag.c" */
  34.  
  35. #include <stdio.h>
  36. #include <io.h>
  37. #include <fcntl.h>
  38. #include <string.h>
  39. #include <stdlib.h>
  40. #include <sys\stat.h>
  41. #include <dos.h>
  42. #include <alloc.h>
  43. #include <time.h>
  44. #include <mem.h>
  45. #include <dir.h>
  46. #include <errno.h>
  47. #include "vardec.h"
  48.  
  49. #define DEFRAG_VER "1.10"
  50.  
  51. configrec syscfg;
  52. statusrec status;
  53. subboardrec subboards[MAX_SUBS];
  54. unsigned int num_subs, nummsgs;
  55. postrec *msgs;
  56. char gatfn[81];
  57. short *gat;
  58. int curdrive, conf_count, conf_scan[MAX_SUBS], scan_email, automated, assume_y;
  59. long messages, totmsgsize, msg_no_text;
  60. time_t program_start;
  61.  
  62.  
  63. /*************************************************************************/
  64. /****************** Wayne Bell's Code (slightly modified) ****************/
  65. /*************************************************************************/
  66.  
  67.  
  68. long dfree(int dr)
  69. /* returns number of bytes available on specified drive */
  70. {
  71.   long d;
  72.   struct dfree df;
  73.  
  74.   getdfree(dr,&df);
  75.   d = df.df_avail;
  76.   d *= (df.df_bsec);
  77.   d *= (df.df_sclus);
  78.   if (df.df_sclus<0)
  79.     d = -1.0;
  80.   return(d);
  81. }
  82.  
  83.  
  84. void save_status()
  85. /* saves system status in memory to disk */
  86. {
  87.   char s[80];
  88.   int statusfile;
  89.  
  90.   sprintf(s,"%sSTATUS.DAT",syscfg.datadir);
  91.   statusfile=open(s,O_RDWR | O_BINARY);
  92.   write(statusfile, (void *)(&status), sizeof(statusrec));
  93.   close(statusfile);
  94. }
  95.  
  96.  
  97. void get_status()
  98. /* retrieves system status from disk into memory */
  99. {
  100.   char s[81];
  101.   int statusfile;
  102.  
  103.   sprintf(s,"%sSTATUS.DAT",syscfg.datadir);
  104.   statusfile=open(s,O_RDWR | O_BINARY);
  105.   if (statusfile>=0) {
  106.     read(statusfile,(void *)(&status), sizeof(statusrec));
  107.     close(statusfile);
  108.   } else
  109.     status.wwiv_version = 0;
  110. }
  111.  
  112.  
  113. void iscan(int b)
  114. /* loads information about message base #b into memory */
  115. {
  116.   int f;
  117.   char s[81];
  118.  
  119.   nummsgs = 0;
  120.   sprintf(s, "%s%s.SUB", syscfg.datadir, subboards[b].filename);
  121.   f = open(s, O_BINARY | O_RDWR);
  122.   if (f == -1) {
  123.     f = open(s, O_BINARY | O_RDWR | O_CREAT,S_IREAD | S_IWRITE);
  124.     msgs[0].owneruser = 0;
  125.     write(f, (void *)(&msgs[0]), sizeof(postrec));
  126.   }
  127.   lseek(f, 0L, SEEK_SET);
  128.   nummsgs = (read(f, (void *)(&msgs[0]),255*sizeof(postrec)) / sizeof(postrec))-1;
  129.   nummsgs = msgs[0].owneruser;
  130.   close(f);
  131. }
  132.  
  133.  
  134. void savebase(int b)
  135. /* saves message information in memory to disk */
  136. {
  137.   int f;
  138.   char s[81];
  139.  
  140.   sprintf(s, "%s%s.SUB", syscfg.datadir, subboards[b].filename);
  141.   f = open(s, O_RDWR | O_BINARY | O_TRUNC | O_CREAT, S_IREAD | S_IWRITE);
  142.   lseek(f, 0L, SEEK_SET);
  143.   msgs[0].owneruser = nummsgs;
  144.   write(f, (void *)(&msgs[0]), ((nummsgs+1) * sizeof(postrec)));
  145.   close(f);
  146. }
  147.  
  148.  
  149. int open_file(char *fn)
  150. /* opens a WWIV Type-2 data file */
  151. {
  152.   int f,i;
  153.   char s[81];
  154.  
  155.   sprintf(s,"%s%s.DAT",syscfg.msgsdir,fn);
  156.   f=open(s,O_RDWR | O_BINARY);
  157.   if (f<0) {
  158.     f=open(s,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
  159.     for (i=0; i<2048; i++)
  160.       gat[i]=0;
  161.     write(f,(void *)gat,4096);
  162.     strcpy(gatfn,fn);
  163. /*    chsize(f,4096L + (75L * 1024L)); */
  164.   }
  165.   if (strcmp(gatfn,fn)) {
  166.     lseek(f,0L,SEEK_SET);
  167.     read(f,(void *)gat,4096);
  168.     strcpy(gatfn,fn);
  169.   }
  170.   return(f);
  171. }
  172.  
  173.  
  174. void remove_link(messagerec *m1, char *aux)
  175. /* deletes a message */
  176. {
  177.   messagerec m;
  178.   char s[81],s1[81];
  179.   int f;
  180.   long csec,nsec;
  181.  
  182.   m=*m1;
  183.   strcpy(s,syscfg.msgsdir);
  184.   switch(m.storage_type) {
  185.     case 0:
  186.     case 1:
  187.       ltoa(m.stored_as,s1,16);
  188.       if (m.storage_type==1) {
  189.         strcat(s,aux);
  190.         strcat(s,"\\");
  191.       }
  192.       strcat(s,s1);
  193.       unlink(s);
  194.       break;
  195.     case 2:
  196.       f=open_file(aux);
  197.       csec=m.stored_as;
  198.       while ((csec>0) && (csec<2048)) {
  199.         nsec=(long) gat[csec];
  200.         gat[csec]=0;
  201.         csec=nsec;
  202.       }
  203.       lseek(f,0L,SEEK_SET);
  204.       write(f,(void *)gat,4096);
  205.       close(f);
  206.       break;
  207.     default:
  208.       /* illegal storage type */
  209.       break;
  210.   }
  211. }
  212.  
  213.  
  214. void savefile(char *b, long l1, messagerec *m1, char *aux)
  215. /* saves a message in memory to disk */
  216. {
  217.   int f,gatp,i5,i4,gati[128];
  218.   messagerec m;
  219.   char s[81],s1[81];
  220.  
  221.   m=*m1;
  222.   switch(m.storage_type) {
  223.     case 0:
  224.     case 1:
  225.       m.stored_as=status.qscanptr++;
  226.       save_status();
  227.       ltoa(m.stored_as,s1,16);
  228.       strcpy(s,syscfg.msgsdir);
  229.       if (m.storage_type==1) {
  230.         strcat(s,aux);
  231.         strcat(s,"\\");
  232.       }
  233.       strcat(s,s1);
  234.       f=open(s,O_RDWR | O_CREAT | O_BINARY,S_IREAD | S_IWRITE);
  235.       write(f, (void *)b,l1);
  236.       close(f);
  237.       break;
  238.     case 2:
  239.       f=open_file(aux);
  240.       gatp=0;
  241.       i5=(int) ((l1 + 511L)/512L);
  242.       i4=1;
  243.       while ((gatp<i5) && (i4<2048)) {
  244.         if (gat[i4]==0)
  245.           gati[gatp++]=i4;
  246.         ++i4;
  247.       }
  248.       gati[gatp]=-1;
  249.       for (i4=0; i4<i5; i4++) {
  250.         lseek(f,4096L + 512L * (long)(gati[i4]),SEEK_SET);
  251.         write(f,(void *)(&b[i4*512]),512);
  252.         gat[gati[i4]]=gati[i4+1];
  253.       }
  254.       lseek(f,0L,SEEK_SET);
  255.       write(f,(void *)gat,4096);
  256.       close(f);
  257.       m.stored_as=(long) gati[0];
  258.       break;
  259.     case 255:
  260.       f=open(aux,O_RDWR | O_CREAT | O_BINARY,S_IREAD | S_IWRITE);
  261.       write(f, (void *)b,l1);
  262.       close(f);
  263.       break;
  264.     default:
  265. /*      printf("Illegal storage type of %u on save!", m.storage_type); */
  266.       break;
  267.   }
  268.   farfree((void *)b);
  269.   *m1=m;
  270. }
  271.  
  272.  
  273. char *readfile(messagerec *m1, char *aux, long *l)
  274. /* reads a message from disk into memory */
  275. {
  276.   int f,i,i1,csec;
  277.   long l1,l2;
  278.   char *b,s[81],s1[81];
  279.   messagerec m;
  280.  
  281.   *l=0L;
  282.   m=*m1;
  283.   switch(m.storage_type) {
  284.     case 0:
  285.     case 1:
  286.       strcpy(s,syscfg.msgsdir);
  287.       ltoa(m.stored_as,s1,16);
  288.       if (m.storage_type==1) {
  289.         strcat(s,aux);
  290.         strcat(s,"\\");
  291.       }
  292.       strcat(s,s1);
  293.       f=open(s,O_RDONLY | O_BINARY);
  294.       if (f==-1) {
  295.         *l=0L;
  296.         return(NULL);
  297.       }
  298.       l1=filelength(f);
  299.       if ((b=farmalloc(l1))==NULL) {
  300.         close(f);
  301.         return(NULL);
  302.       }
  303.       read(f,(void *)b,l1);
  304.       close(f);
  305.       *l=l1;
  306.       break;
  307.     case 2:
  308.       f=open_file(aux);
  309.       csec=m.stored_as;
  310.       l1=0;
  311.       while ((csec>0) && (csec<2048)) {
  312.         l1+=512L;
  313.         csec=gat[csec];
  314.       }
  315.       if (!l1) {
  316. /*        printf("\nNo message found.\n\n"); */
  317.         return(NULL);
  318.       }
  319.       if ((b=farmalloc(l1))==NULL)
  320.         return(NULL);
  321.       csec=m.stored_as;
  322.       l1=0;
  323.       while ((csec>0) && (csec<2048)) {
  324.         lseek(f,4096L + 512L*csec,SEEK_SET);
  325.         l1+=(long)read(f,(void *)(&(b[l1])),512);
  326.         csec=gat[csec];
  327.       }
  328.       close(f);
  329.       l2=l1-512;
  330.       while ((l2<l1) && (b[l2]!=26))
  331.         ++l2;
  332.       *l=l2;
  333.       break;
  334.     case 255:
  335.       f=open(aux,O_RDONLY | O_BINARY);
  336.       if (f==-1) {
  337.         *l=0L;
  338.         return(NULL);
  339.       }
  340.       l1=filelength(f);
  341.       if ((b=farmalloc(l1+256L))==NULL)
  342.         return(NULL);
  343.       read(f,(void *)b,l1);
  344.       close(f);
  345.       *l=l1;
  346.       break;
  347.     default:
  348.       /* illegal storage type */
  349.       *l=0L;
  350.       b=NULL;
  351.       break;
  352.   }
  353.   return(b);
  354. }
  355.  
  356.  
  357. /*************************************************************************/
  358. /****************** Wayne Bell's Code (slightly modified) ****************/
  359. /*************************************************************************/
  360.  
  361.  
  362. int get_next_email(int inf, int outf, mailrec *m)
  363. {
  364.   int rc=1;
  365.   mailrec m1, m2;
  366.   long l, l1;
  367.  
  368.   read(inf, (void *)(&m1), sizeof(mailrec));
  369.   if (m1.status & status_multimail) {
  370.     lseek(outf, 0, SEEK_SET);
  371.     l = filelength(outf) / sizeof(mailrec);
  372.     l1 = 0;
  373.     while (l1 < l) {
  374.       l1++;
  375.       read(outf, (void *)(&m2), sizeof(mailrec));
  376.       if (m2.msg.stored_as == m1.msg.stored_as)
  377.     l1 = 0xFFFFFFFF;
  378.     }
  379.     lseek(outf, 0, SEEK_END);
  380.   }
  381.   if (l1 == 0xFFFFFFFF)
  382.     rc = 0;
  383.   *m = m1;
  384.   return(rc);
  385. }
  386.  
  387.  
  388. void defrag_email()
  389. {
  390.   char s[81], s1[81], s2[81], *temp_msg_buf;
  391.   int f, f1, f2, i, i1, i2;
  392.   long len, num_email;
  393.   mailrec mr;
  394.  
  395.   printf("Reading EMAIL.DAT...\r");
  396.   sprintf(s1, "%sTEMP$$$!.DAT", syscfg.msgsdir);
  397.   unlink(s1);
  398.   sprintf(s1, "%sTEMP$$$!.DAT", syscfg.datadir);
  399.   unlink(s1);
  400.   sprintf(s, "%sEMAIL.DAT", syscfg.datadir);
  401.   f1 = open(s, O_RDWR | O_BINARY);
  402.   if (f1 < 0) {
  403.     printf("%s NOT FOUND.\n", s);
  404.     exit(1);
  405.   }
  406.   num_email = (filelength(f1) / sizeof(mailrec));
  407.   sprintf(s1, "%sTEMP$$$!.DAT", syscfg.datadir);
  408.   f2 = open(s1, O_RDWR | O_CREAT | O_BINARY | O_TRUNC, S_IREAD | S_IWRITE);
  409.   if (f2 < 0) {
  410.     printf("%s NOT CREATED.\n", s);
  411.     close(f1);
  412.     exit(1);
  413.   }
  414.   i1 = 0;
  415.   f = open_file("EMAIL");
  416.   if ((dfree(curdrive) > filelength(f)) && (f > 0)) {
  417.     close(f);
  418.     for (i1 = 0; i1 < num_email; i1++) {
  419.       printf("De-fragging EMAIL.DAT (%d/%d)...\r", (i1 + 1), num_email);
  420.       if (get_next_email(f1, f2, &mr))
  421.         if ((mr.touser != 0) || (mr.tosys != 0)) {
  422.           temp_msg_buf = readfile(&mr.msg, "EMAIL", &len);
  423.           if (temp_msg_buf != NULL) {
  424.             totmsgsize += len;
  425.             savefile(temp_msg_buf, len, &mr.msg, "TEMP$$$!");
  426.           } else {
  427.             msg_no_text++;
  428.             mr.touser = 0;
  429.             mr.tosys = 0;
  430.           }
  431.         }
  432.       messages++;
  433.       if ((mr.touser != 0) || (mr.tosys != 0))
  434.         write(f2, (void *)(&mr), sizeof(mailrec));
  435.     }
  436.     sprintf(s, "%sEMAIL.DAT", syscfg.msgsdir);
  437.     sprintf(s1, "%sTEMP$$$!.DAT", syscfg.msgsdir);
  438.     unlink(s);
  439.     f = rename(s1, s);
  440.     if (f == 0) {
  441.       printf("\n");
  442.       sprintf(s, "%sEMAIL.DAT", syscfg.datadir);
  443.       sprintf(s1, "%sTEMP$$$!.DAT", syscfg.datadir);
  444.       unlink(s);
  445.       f = rename(s1, s);
  446.       if (f != 0) {
  447.         printf("De-fragging EMAIL.DAT (ERROR!)...    \n");
  448.         switch(errno) {
  449.           case ENOENT:
  450.             strcpy(s2, "No such file");
  451.             break;
  452.           case EACCES:
  453.             strcpy(s2, "Permission denied");
  454.             break;
  455.           case ENOTSAM:
  456.             strcpy(s2, "Not same device");
  457.             break;
  458.         }
  459.         printf("  (Could not rename temporary file; REASON: %s\n", s2);
  460.         unlink(s1);
  461.         sprintf(s, "%sEMAIL.DAT", syscfg.msgsdir);
  462.         unlink(s);
  463.       }
  464.     } else {
  465.       printf("De-fragging EMAIL.DAT (ERROR!)...    \n");
  466.       switch(errno) {
  467.         case ENOENT:
  468.           strcpy(s2, "No such file");
  469.           break;
  470.         case EACCES:
  471.           strcpy(s2, "Permission denied");
  472.           break;
  473.         case ENOTSAM:
  474.           strcpy(s2, "Not same device");
  475.           break;
  476.       }
  477.       printf("  (Could not rename temporary file; REASON: %s\n", s2);
  478.       unlink(s1);
  479.       sprintf(s, "%sEMAIL.DAT", syscfg.datadir);
  480.       sprintf(s1, "%sTEMP$$$!.DAT", syscfg.datadir);
  481.       unlink(s);
  482.       unlink(s1);
  483.     }
  484.   } else {
  485.     if (f > 0)
  486.       close(f);
  487.     printf("Reading EMAIL.DAT (NOT ENOUGH DISK SPACE!)...\n");
  488.   }
  489. }
  490.  
  491.  
  492. void delete(int mn)
  493. {
  494.   int i;
  495.  
  496.   if ((mn > 0) && (mn <= nummsgs)) {
  497.     for (i = mn; i < nummsgs; i++)
  498.       msgs[i] = msgs[i + 1];
  499.     nummsgs--;
  500.   }
  501. }
  502.  
  503.  
  504. void defrag(int b)
  505. {
  506.   char s[81], s1[81], s2[81], *temp_msg_buf;
  507.   int f, i, i1, i2;
  508.   long len;
  509.  
  510.   printf("Reading %s...\r", subboards[b].name);
  511.   sprintf(s1, "%sTEMP$$$!.DAT", syscfg.msgsdir);
  512.   unlink(s1);
  513.   iscan(b);
  514.   i1 = 0;
  515.   if (subboards[b].storage_type == 2) {
  516.     f = open_file(subboards[b].filename);
  517.     if ((dfree(curdrive) > filelength(f)) && (f > 0)) {
  518.       close(f);
  519.       for (i1 = 1; i1 <= nummsgs; i1++) {
  520.         temp_msg_buf = readfile(&msgs[i1].msg, subboards[b].filename, &len);
  521.         if (temp_msg_buf != NULL) {
  522.           savefile(temp_msg_buf, len, &msgs[i1].msg, "TEMP$$$!");
  523.           totmsgsize += len;
  524.         } else {
  525.           delete(i1);
  526.           msg_no_text++;
  527.         }
  528.         messages++;
  529.         printf("De-fragging %s (%d/%d)...\r", subboards[b].name, i1, nummsgs);
  530.       }
  531.       sprintf(s, "%s%s.DAT", syscfg.msgsdir, subboards[b].filename);
  532.       sprintf(s1, "%sTEMP$$$!.DAT", syscfg.msgsdir);
  533.       unlink(s);
  534.       f = rename(s1, s);
  535.       if (f == 0) {
  536.         printf("\n");
  537.         savebase(b);
  538.       } else {
  539.         printf("De-fragging %s (ERROR!)...    \n", subboards[b].name);
  540.         switch(errno) {
  541.           case ENOENT:
  542.             strcpy(s2, "No such file");
  543.             break;
  544.           case EACCES:
  545.             strcpy(s2, "Permission denied");
  546.             break;
  547.           case ENOTSAM:
  548.             strcpy(s2, "Not same device");
  549.             break;
  550.         }
  551.         printf("  (Could not rename temporary file; REASON: %s\n", s2);
  552.         unlink(s);
  553.         unlink(s1);
  554.         sprintf(s, "%s%s.SUB", syscfg.datadir, subboards[b].filename);
  555.         unlink(s);
  556.       }
  557.     } else {
  558.       if (f > 0)
  559.         close(f);
  560.       printf("Reading %s (NOT ENOUGH DISK SPACE!)...\n", subboards[b].name);
  561.     }
  562.   } else {
  563.     printf("Reading %s...Ignored.  (Storage type not 2)\n", subboards[b].name);
  564.   }
  565. }
  566.  
  567.  
  568. void report()
  569. {
  570.   time_t end_run;
  571.  
  572.   printf("\n\n");
  573.   printf("========================================\n");
  574.   printf("%10ld messages processed.\n", messages);
  575.   printf("%10ld bytes (%ldk) processed.\n", totmsgsize);
  576.   printf("%10ld bytes per average message.\n", (totmsgsize / messages));
  577.   time(&end_run);
  578.   printf("%10ld seconds elapsed.\n", (end_run - program_start));
  579.   if (msg_no_text)
  580.     printf("%10ld message(s) with no text removed.\n", msg_no_text);
  581.   printf("========================================\n\n");
  582. }
  583.  
  584.  
  585. void main(int argc, char *argv[])
  586. {
  587.   char s[81], s1[81], s2[81], ch;
  588.   int f, i, i1, i2;
  589.   long len;
  590.  
  591.   time(&program_start);
  592.   conf_count = 0;
  593.   scan_email = 0;
  594.   messages = 0;
  595.   totmsgsize = 0;
  596.   msg_no_text = 0;
  597.   automated = 0;
  598.   assume_y = 0;
  599.   printf("\nDeFrag v%s - Defragment (compress) WWIV type-2 message bases\n", DEFRAG_VER);
  600.   printf("Copyright (c) 1991 by Jeff Garzik\n\n");
  601.   sprintf(s, "CONFIG.DAT");
  602.   f = open(s, O_RDWR | O_BINARY);
  603.   if (f < 0) {
  604.     printf("%s NOT FOUND.\n", s);
  605.     exit(1);
  606.   }
  607.   read(f, (void *)(&syscfg), sizeof(configrec));
  608.   close(f);
  609.   get_status();
  610.   if (status.wwiv_version == 0) {
  611.     printf("STATUS.DAT NOT READ.\n");
  612.     exit(1);
  613.   }
  614.   itoa(status.wwiv_version, s, 10);
  615.   s[5] = s[4];
  616.   s[4] = s[3];
  617.   s[3] = s[2];
  618.   s[2] = s[1];
  619.   s[1] = '.';
  620.   printf("Compiled under %s, running under WWIV v%s.\n\n", VERSION_NUMBER, s);
  621.   sprintf(s, "%sSUBS.DAT", syscfg.datadir);
  622.   f = open(s, O_RDWR | O_BINARY);
  623.   if (f < 0) {
  624.     printf("%s NOT FOUND.\n", s);
  625.     exit(1);
  626.   }
  627.   num_subs = (read(f, subboards, (MAX_SUBS*sizeof(subboardrec))))/
  628.            sizeof(subboardrec);
  629.   close(f);
  630.   if (num_subs < 1) {
  631.     printf("No subs to compress.\n");
  632.     exit(1);
  633.   }
  634.   for (i=1; i<argc; i++) {
  635.     strcpy(s,argv[i]);
  636.     if ((s[0]=='-') || (s[0]=='/')) {
  637.       ch = toupper(s[1]);
  638.       switch(ch) {
  639.         case 'A':                      /* enable/disable unattended mode */
  640.           switch (s[2]) {
  641.             case 0:
  642.             case '+':
  643.               automated = 1;
  644.               break;
  645.             case '-':
  646.               automated = 0;
  647.               break;
  648.           }
  649.           break;
  650.         case 'C':                      /* select subs to defrag */
  651.           if (conf_count < 0)
  652.             conf_count = 0;
  653.           i1 = atoi(&(s[2]));
  654.           if ((conf_count == 0) && (i1 >= 0) && (i1 < num_subs)) {
  655.             conf_scan[conf_count] = i1;
  656.             conf_count++;
  657.           } else {
  658.             for (i2 = 0; i2 < conf_count; i2++)
  659.               if (conf_scan[i2] == i1)
  660.                 break;
  661.             if (i2 >= conf_count) {
  662.               conf_scan[conf_count] = i1;
  663.               conf_count++;
  664.             }
  665.           }
  666.           break;
  667.         case 'E':                      /* enable/disable EMAIL.DAT defrag */
  668.           switch (s[2]) {
  669.             case 0:
  670.             case '+':
  671.               scan_email = 1;
  672.               break;
  673.             case '-':
  674.               scan_email = 0;
  675.               break;
  676.           }
  677.           break;
  678.         case 'O':                      /* only scan EMAIL.DAT */
  679.           conf_count = -1;
  680.           scan_email = 1;
  681.           break;
  682.         case 'Y':                      /* How to answer Y/N questions */
  683.           switch (s[2]) {              /* in unattended mode          */
  684.             case 0:
  685.             case '+':
  686.               assume_y = 1;
  687.               break;
  688.             case '-':
  689.               assume_y = 0;
  690.               break;
  691.           }
  692.           break;
  693.       }
  694.     }
  695.   }
  696.   msgs = (postrec *)farmalloc((long)(255 * sizeof(postrec)));
  697.   if (msgs == NULL) {
  698.     printf("Not enough memory.\n");
  699.     exit(1);
  700.   }
  701.   gat = (short *)farmalloc(2048 * sizeof(short));
  702.   if (gat == NULL) {
  703.     printf("Not enough memory.\n");
  704.     exit(1);
  705.   }
  706.   if (syscfg.msgsdir[1] == ':')
  707.     curdrive = (int)(syscfg.msgsdir[0] - 'A' + 1);
  708.   else
  709.     curdrive = getdisk();
  710.   if (scan_email)
  711.     defrag_email();
  712.   if (conf_count == 0) {
  713.     for (i = 0; i < num_subs; i++)
  714.       defrag(i);
  715.   } else {
  716.     for (i = 0; i < conf_count; i++)
  717.       defrag(conf_scan[i]);
  718.   }
  719.   report();
  720. }
  721.  
  722.